package office.stock.persistance;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import office.stock.model.User;

@Stateless
public class UserDAO extends AbstractGenericDAO<User> {

    @Override
    public Class<User> getEntityClass() {
	return User.class;
    }

    @SuppressWarnings("unchecked")
    public User getByEmail(String email) {
	Query query =entityManager.createNamedQuery("User.findByEmail").setParameter("email", email);
	List<User> usersList = query.getResultList();
	User user = null;
	if (usersList != null && !usersList.isEmpty()) {
	    user = usersList.get(0);
	}
	return user;
    }
}
